<?php
/**
 * Created by PhpStorm.
 * User: zq
 * Date: 2017/2/20
 * Time: 15:17
 */

namespace Common\Model;


use Think\Model;

class UserModel extends Model
{
    public function login(){
        $username = I('post.username');
        $password = md5(I('post.password'));
        $code = I('post.code');
        $data = M('user')->find();
//      dump($data);die;
        if($data['sh_uname']!=$username){
            $this->error = '用户名不存在';
            return false;
        }
        if($data['sh_password'] !=$password){
            $this->error ='密码不正确';
            return false;
        }
        if(!$this->check_verify($code)){
            $this->error ='验证码错误';
            return false;
        }
        session('name',$username);
        session('uid',$data['sh_uid']);
//        print_r($_SESSION);die;
        return true;
    }
    function check_verify($code, $id = '')
    {
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }

}